import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const store = new Vuex.Store({
	state:{
		userInfo:null,
	},
	mutations:{
		setUserInfo(state,userInfo){
			state.userInfo=userInfo
		}
	},
	actions:{
		setUserInfo({commit},userInfo){
			uni.setStorageSync("userInfo",userInfo);
			commit("setUserInfo",userInfo);
		}
	},
	getters:{
		userInfo(state){
			if(state.userInfo){
				return state.userInfo;
			}
			else{
				var userInfo=uni.getStorageSync("userInfo");
				if(userInfo){
					state.userInfo=userInfo;
					return userInfo;
				}
				else{
					return null;
				}
			}
		}
	}
});
export default store;